package com.ibuonline.b2b.system.action;


import com.opensymphony.oscache.base.Cache; 
import com.opensymphony.oscache.web.ServletCacheAdministrator;
import com.dimeng.common.base.BaseAction;
import com.ibuonline.b2b.common.CacheUtil;

public class CacheManageAction extends BaseAction {

	private static final long serialVersionUID = -5552807551678432254L;
	
	private String key;
	private String pattern;
	private String loginName;
	private Integer companyId;
	
	@SuppressWarnings("deprecation")
	public void flushOSCache() {
		Cache cache = ServletCacheAdministrator.getInstance(
				getSession().getServletContext()).getAppScopeCache(getSession().getServletContext());
		if ("true".equals(pattern))
			cache.flushPattern(key);
		else
			cache.flushEntry(key);
		System.out.println("flush " + key + " successfully!");
		getOut().print("OK");
		getOut().flush();
	}
	
	public void flushAllHostOSCache() {
		try {
			CacheUtil.getInstance().flushPage(key, pattern);
			getOut().print("OK");
			getOut().flush();
		} catch (Exception e) {
			e.printStackTrace();
			getOut().print("Failed");
			getOut().flush();
		}
	}
	
	public void flushGoldShop() {
		CacheUtil.getInstance().flushGoldShop(loginName);
	}
	
	public void flushFreeShop() {
		CacheUtil.getInstance().flushFreeShop(companyId);
	}
	
	public String getKey() {
		return key;
	}
	
	public void setKey(String key) {
		this.key = key;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public Integer getCompanyId() {
		return companyId;
	}

	public void setCompanyId(Integer companyId) {
		this.companyId = companyId;
	}

	public String getPattern() {
		return pattern;
	}

	public void setPattern(String pattern) {
		this.pattern = pattern;
	}
}
